Class: modelit.web.server.Server

Extends: matlab.mixin.SetGet & handle

DESCRIPTION:

Create a HTTP server, that listens to a specific port and processes requests through the specified callback.

Properties

hostname string
  The hostname to which the server is listening
  Default value: 'localhost'
port integer|NaN
  The port to which the server is listening
  NaN if no server is active.
running boolean
  Status of the server

Public Method: Server

DESCRIPTION:

Create a HTTP server, that listens to a specific port and processes requests through the specified callback.

CALL:

obj = Server(hostname, port, callback, keystore, keystorepassword, keymanagerpassword)

INPUT:

hostname string
name of the host on which the server runs, e.g. localhost or the Docker container name.
port integer
port on which the server is listening.
callback function
(optional) if not specified the server does not process
any requests. The signature of callback is
callback(event), where "event" is an object of type
modelit.web.server.HttpExchange. The function callback
produces no output argument, but must use the method
event.send when done.
keystore string
(optional) filename of the .jks file.
keystorepassword string
(optional) Password for the keystore.
keymanagerpassword string
(optional) Password for the keymanager.

OUTPUT:

obj modelit.web.server.Server
Documentation for modelit.web.server.Server/Server
   doc modelit.web.server.Server

Public Method: stop

DESCRIPTION:

Stop the server.

CALL:

obj = stop(obj)

INPUT:

obj modelit.web.server.Server

OUTPUT:

obj modelit.web.server.Server
The server is stopped.

Public Method: start

DESCRIPTION:

Start the server to listen on the selected port.

CALL:

obj = start(obj)

INPUT:

obj modelit.web.server.Server

OUTPUT:

obj modelit.web.server.Server
the servers is started and listens to the selected port.

Public Method: removeContext

DESCRIPTION:

Remove a callback for the specified path.

CALL:

removeContext(obj, path)

INPUT:

obj modelit.web.server.Server
path string
The path from which the callback has to be removed.
Note that adding a different context removes the old
context, so no explicit removal of the context is
needed.

OUTPUT:

     No direct output, the callback for the specified path has
     been removed.

Public Method: addContext

DESCRIPTION:

Add a callback for request on the specified port. Username and password can be specified to require authentication on this specific path.

CALL:

addContext(obj, path, callback, username, password)

INPUT:

obj modelit.web.server.Server
path string
valid URL path, e.g. /resource/value
callback any
<(modelit.web.server.HttpExchange) => void>
the HttpExchange object contains all information of the
request and all methods to return a response to the
sender.
username string
optional username when authentication is needed.
password string
optional password when authentication is needed.

OUTPUT:

      No output.

Private Method: processRequest

DESCRIPTION:

Callback executed when the server receives a request. It triggers a second callback in which the callback provided by the user is called with a modelit.web.server.HttpExchange object containing all the necessary information of the request and all the methods to send a response back the sender.

CALL:

processRequest(obj, event, currentContextCallback)

INPUT:

obj any
event nl.modelit.web.server.ServerEvent
Java object.
currentContextCallback functionhandle
The callback specified by the user for the current
context, executed with a
modelit.web.server.HttpExchange object containing all
the necessary information of the request and all the
methods to send a response back the sender.

OUTPUT:

     No output.